﻿@model qkview.Models.BoardModels

@{
    ViewBag.Title = ViewBag.DisplayName + "'s Boards - QKView";
    var lst = Model.ListModel;
    var createModel = Model.CreateModel; 
}

<div class="metaBar">    
    <div id="socialBar">
        @Html.Partial("_SocialShare") 
    </div>
    <div class="author">
        QKView by <a href="@Url.RouteUrl("Board", new { username = @ViewBag.ReqestedUserName }) ">@ViewBag.DisplayName</a>
    </div>
</div>


@if (ViewBag.IsEdit)
{
@* used for ajax in AddAntiForgeryToken() *@
    <form id="__AjaxAntiForgeryForm" action="#" method="post" autocomplete="off">@Html.AntiForgeryToken()</form>  
    
    <h2 style="display: inline-block">My Boards:</h2>
    <div style="float: right; margin: 0.7em 0;">
        <a id="aAddNew" class="linkButton" href="javascript:void(0)">Add New Board</a>
    </div>
    <div id="CreateBoard" style="display: none; width: 750px" title="Add New Board">
        @{
    Html.RenderPartial("Create", createModel);        
        }
    </div>
    <p class="errorMsg" style="color:red"></p>
    <ul class="archiveList">
        @foreach (var item in lst)
        {
            <li>
                <h3>
                    <a href="@Url.RouteUrl("Note", new { username = @ViewBag.ReqestedUserName, boardurl = @item.URLSlug })?edit=1">@item.Title</a>
                </h3>
                <p>
                    @Html.DisplayFor(modelItem => item.Description)

                </p>
                <div class="metadata">Category: 
                    @Html.DisplayFor(modelItem => item.Category.Name)
                    @Html.ActionLink("Edit", "Edit", new { id = qkview.Models.Common.Encode(item.BoardID.ToString()) })
                    @Html.ActionLink("Delete", "DeleteConfirmed", new object { }, new { @class = "delete", data_id = @qkview.Models.Common.Encode(item.BoardID.ToString()) })

                </div>
            </li>
        }
    </ul>
}
else
{
    <h2 style="display: inline-block">Boards:</h2>


    <ul class="archiveList">
        @foreach (var item in lst)
        {
            <li>
                <h3>
                    <a href="@Url.RouteUrl("Note", new { username = @ViewBag.ReqestedUserName, boardurl = @item.URLSlug })">@item.Title</a>
                </h3>
                <p>
                    @Html.DisplayFor(modelItem => item.Description)
                </p>
                <div class="metadata">Category: 
                    @Html.DisplayFor(modelItem => item.Category.Name)
                </div>
            </li>
        }
    </ul>

}
    @section header{
     <meta name="description" content="@(ViewBag.DisplayName + "'s Boards, topics and description - QKView")" />
           <meta name="keywords" content="@ViewBag.Title,QKView, quick view, boards, topics" />
        }
@section Scripts {
    @Scripts.Render("~/bundles/jqueryui")
    @Scripts.Render("~/bundles/jqueryval")
    @Scripts.Render("~/bundles/ajaxlogin")
    @if (ViewBag.IsEdit)
    {
        <script type="text/javascript">
            $(function () {
                $('#aAddNew').click(function (e) {
                    e.preventDefault();
                    $('#CreateBoard').dialog({
                        autoOpen: true,
                        show: 'slide',
                        width: 750,
                        modal: true,
                        close: function () {
                            $(this).find('form')[0].reset();
                        }
                    });

                });
            })
             
            var AddAntiForgeryToken = function (data) {
                 data.__RequestVerificationToken = $('#__AjaxAntiForgeryForm input[name=__RequestVerificationToken]').val();
                 return data;
             };

             $('a.delete').click(function (event) 
             {
                 var $self = $(this);
                 event.preventDefault(); 
                 var url =  $self.attr('href');
                 if (confirm('Do you really want to delete?')){
                     $.ajax({
                         type: "post",
                         dataType: "html",
                         url: url,
                         data: AddAntiForgeryToken({ id: $self.attr("data-id") })
                     })
                     .done(function (json) {
                         json = $.parseJSON(json) || {};
                         if (json.success) {
                             location.reload();
                         }
                         else if (json.errors) {
                             displayError(json.errors);
                         }
                     })
                     .fail(function () {
                         displayError(['An unknown error happened.']);
                     })
                         ;
                 }
             })
             function displayError(msg) {
                 $('.errorMsg').html('');
                 $('.errorMsg').append(msg);
             }

        </script>
    }

}
